package com.kclm.se.socket;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class SimpleServer {

	public static void main(String[] args) {
		final int port = 10080;
		List<Socket> allClients = new LinkedList<Socket>();
		try {
			ServerSocket server = new ServerSocket(port);
			System.out.printf("服务器启动，在%d端口监听 \n", port);
			while(true) {
				//
				Socket client = server.accept(); //block method
				//
				allClients.add(client);
				//要么使用当前线程去服务，要么创建新的线程 去服务
				Thread t = new ServerThread(client, allClients);
				t.start();
				//
				System.out.printf("由线程：%s 服务..., 当前客户数：%d \n",t.getName(),allClients.size());
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
